package org.javaboy.web.controller.ai_interview;

import org.javaboy.ai.domain.Models;
import org.javaboy.ai.service.IModelsService;
import org.javaboy.common.annotation.Log;
import org.javaboy.common.core.controller.BaseController;
import org.javaboy.common.core.domain.AjaxResult;
import org.javaboy.common.core.page.TableDataInfo;
import org.javaboy.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author javaboy
 * @since 2024-07-03
 */
@RestController
@RequestMapping("/models")
public class ModelsController extends BaseController {
    @Autowired
    IModelsService modelsService;

    @PreAuthorize("@ss.hasPermi('ai:model:search')")
    @GetMapping("/list")
    public TableDataInfo list(Models models) {
        startPage();
        List<Models> list = modelsService.selectModelsList(models);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('ai:model:add')")
    @Log(title = "模型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Models models) {
        if (modelsService.checkNameExists(models)) {
            return error("新增Models'" + models.getName() + "'失败，Name已存在");
        }
        return toAjax(modelsService.save(models));
    }

    @PreAuthorize("@ss.hasPermi('ai:model:remove')")
    @Log(title = "模型管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{modelsIds}")
    public AjaxResult remove(@PathVariable Long[] modelsIds) {
        return toAjax(modelsService.deleteModels(modelsIds));
    }

    @PreAuthorize("@ss.hasPermi('ai:model:update')")
    @Log(title = "模型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Models models) {
        if (modelsService.checkNameExists(models)) {
            return error("修改Models'" + models.getName() + "'失败，Name已存在");
        }
        return toAjax(modelsService.updateById(models));
    }

    @PreAuthorize("@ss.hasPermi('ai:model:search')")
    @GetMapping(value = "/{modelsId}")
    public AjaxResult getInfo(@PathVariable Integer modelsId) {
        return success(modelsService.getById(modelsId));
    }
}
